package com.tjh.springbootapi.service;

import com.tjh.springbootapi.handles.WebSocketHandle;
import com.tjh.springbootapi.utils.ShaUtil;
import com.tjh.springbootapi.webSocket.ChannelSupervise;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Create by koala on 2022-09-05
 */
@Service
public class WebSocketService {

    public String getWebSocketKey() {
        String girdKey = "userId" + "_" + new Date();
        String socketKey = ShaUtil.SHAEncrypt(girdKey);
        ChannelSupervise.socketKeyMap.put(socketKey, "userId");
        return socketKey;
    }

    public void sedDataToWebSocket(String info) {
        new Thread(new WebSocketHandle(info)).start();
    }

}